import requests

from api.p2p_reg_login import Reg_Login
from confing import BASE_URL


class ApproveTrust(object):

    # 初始化方法:设置实例属性
    def __init__(self, session):
        self.session = session
        self.__approve_url = BASE_URL + "/member/realname/approverealname"
        self.__approve1_url = BASE_URL + "/member/member/getapprove"
        self.__approve2_url = BASE_URL + "/trust/trust/register"
        self.__approve3_url = BASE_URL + "/common/public/verifycode/{}"
        self.__approve4_url = BASE_URL + "/trust/trust/register"

    # 定义接口方法
    def approve(self, data):  # 实名认证
        file = {"a": "b"}
        # 发送请求
        res = self.session.post(url=self.__approve_url, files=file, data=data)
        return res

    def approve1(self):  # 获取认证信息
        res = self.session.post(url=self.__approve1_url)
        return res

    def approve2(self):
        res = self.session.post(url=self.__approve2_url)
        return res

    def approve3(self,r):
        res = self.session.post(url=self.__approve3_url.format(r))
        return res

    def approve4(self):
        res = self.session.post(url=self.__approve4_url)
        return res


if __name__ == '__main__':
    session = requests.Session()
    reg_login = Reg_Login(session)
    app_trust = ApproveTrust(session)
    # 调用方法:前置登录成功
    data1 = {"keywords": "15012000001",
             "password": "Aa123456"}
    reg_login.login(data1)
    # 调用方法:实名认证
    data = {"realname": "娃哈哈", "card_id": "341125200203077752"}
    res = app_trust.approve(data)
    print(res.json())
